package hao.itheima.mapper;

import hao.itheima.entity.Student;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface StudentMapper {

    /**
     * 根据ID班级id, 查询学生数
     *
     * @param id
     * @return
     */
    @Select("select count(*) from student where clazz_id= #{id}")
    Integer countByClazzId(Integer id);

    /**
     * 分页查询
     * 动态Sql进行开发
     *
     * @param name
     * @param degree
     * @param clazzId
     * @return
     */
    List<Student> list(String name, Integer degree, Integer clazzId);

    /**
     * 批量删除学员
     *
     * @param ids
     */
    //传递的是一个数组, 需要动态Sql
    void deleteBatch(List<Integer> ids);

    /**
     * 新增学员
     *
     * @param student
     */
    @Insert("insert into student(name, no, gender, phone, id_card, is_college, address, " +
            "degree, graduation_date, clazz_id, create_time, update_time)" +
            " values (#{name},#{no},#{gender},#{phone},#{idCard},#{isCollege},#{address},#{degree}," +
            "#{graduationDate},#{clazzId},#{createTime},#{updateTime})")
    void insert(Student student);

    /**
     * 查询回显
     * @param id
     * @return
     */
    @Select("select * from student where id = #{id}")
    Student getById(Integer id);

    /**
     * 修改学员信息
     * @param student
     */

    void update(Student student);

    /**
     * 违纪处理
     * @param id
     * @param score
     */
    @Update("update student set violation_score = (violation_score + #{score}) , violation_count = (violation_count + 1) where id = #{id}")
    void violationScore(Integer id, Integer score);

    /**
     * 统计学员的学历信息
     * @return
     */
    @MapKey("name")
    List<Map<String, Object>> getStudentDegreeData();


    /**
     * 统计每一个班级的人数
     * @return
     */
    //基于XML进行开发
    @MapKey("name")
    List<Map<String, Object>> getStudentCountData();

}
